// import { gp } from '@vui'
import merge from 'lodash/merge'
import isArray from 'lodash/isArray'
import { getModelInfo } from '@ve/utils/getModelInfo'
//必须带done回调 执行完成调用
export default function dataTo({ vm, action, done }) {
  // left
  let modelADatas = {}
  action.extension.aTob.a.forEach((id) => {
    // 查找单个模块信息
    let model_info = getModelInfo(vm, id)
    if (model_info) {
      // 找到data
      modelADatas = merge(modelADatas, model_info['data'])
    }
  })

  // right
  action.extension.aTob.b.forEach((id) => {
    let model_info = getModelInfo(vm, id)
    if (isArray(model_info) && model_info.length <= 0) {
      // gp.$baseMessage('没有找到模块 a-b', 'warning')
      console.warn('没有找到模块 a-b')
      return
    }
    model_info.data = merge(model_info.data, modelADatas)

    vm.$store.dispatch('preview/updateModelInfo', {
      id,
      modelInfo: model_info,
    })
  })
  done(null, {})
}
